
<template>
    <div :class="{'hid-slider': !isOpen}" class="app-container table-wrapper">

        <split-pane @resize="resize" :min-percent="2" :default-percent="defaultPercent" :max-percent="30" split="vertical" ref="split">
            <template slot="paneL">
                <slider :is-open="isOpen" class="slider-wrapper" @toggleSlider="toggleSlider">
                    <el-tabs v-model="leftTabName" @tab-click="handleLeftTabClick" class="left-tab">
                        <el-tab-pane label="查询管理" name="first">
                            <el-form ref="form" :model="filterData" label-width="10px">

                                <!--查询-->
                                <!--分字段类型生成-->

                                <el-form-item label="">
                                    <!--下拉-->
                                    <h3>部门</h3>
                                    <el-select v-model="filterData.EMPVEMPLOYEE_DEPID" placeholder="请选择">
                                        <el-option
                                            v-for="item in dictValues['sql|sql9']"
                                            :key="item.code"
                                            :label="item.name"
                                            :value="item.code"/>
                                    </el-select>
                                </el-form-item>

                                <el-form-item label="">
                                    <!--下拉-->
                                    <h3>后备职务级别</h3>
                                    <el-select v-model="filterData.EMPPREPARCADREREG_CADREGRADE" placeholder="请选择">
                                        <el-option
                                            v-for="item in dictValues['sql|sql63']"
                                            :key="item.code"
                                            :label="item.name"
                                            :value="item.code"/>
                                    </el-select>
                                </el-form-item>

                                <el-form-item label="">
                                    <!--下拉-->
                                    <h3>人员容器</h3>
                                    <el-input v-model="userIds" type="textarea" placeholder="" />
                                </el-form-item>

                                <el-form-item>
                                    <el-button type="primary" @click="searchForm()">查询</el-button>
                                    <el-button @click="resetForm()">重置</el-button>
                                </el-form-item>

                            </el-form>
                        </el-tab-pane>

                    </el-tabs>
                </slider>
            </template>
            <template slot="paneR">

                <table-container
                    ref="pre_cadreReg_list"
                    :form-id="formId"
                    :filter-data="filterData"
                    :common-placeholder="commonPlaceholder"
                    :show-row-column="showRowColumn"
                    :list="list"
                    :list-loading="listLoading"
                    :field-valid="fieldValid"
                    :button-list="buttonList"
                    :has-common-filter = "hasCommonFilter"
                    :fixed-columns = "fixedColumns"
                    :height-percentage = "heightPercentage"
                    :has-tab = "hasTab"
                    :master-table="masterTable"
                    @onSortClick="onSortClick"
                    @loadMore="loadMore"
                    @onRowButtonClick="onRowButtonClick">
                    <el-pagination
                        :current-page="pager.offset"
                        :page-sizes="[10,20,50,100]"
                        :page-size="pager.limit"
                        :total="totalData"
                        layout="total, sizes, prev, pager, next, jumper"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"/>
                </table-container>

            </template>
        </split-pane>

        <el-dialog title="选择导入的Excel" v-if="dialogImportVisible" :visible.sync="dialogImportVisible">
            <import-data :import-excel-data="importExcelData"/>
        </el-dialog>

        <el-dialog title="导出字段" v-if="dialogExportVisible" :visible.sync="dialogExportVisible">
            <export-data :export-excel-data="exportExcelData"/>
        </el-dialog>

    </div>
</template>

<script>
import slider from '@/components/table/slider'
import tableContainer from '@/components/table/table-container'
import pagination from '@/mixins/pagination'
import { queryTreeSolution, removeDataByButton, executeSql } from '@/api/api'
import tableInterface from '@/mixins/tableInterface'
import Cookies from 'js-cookie'
import split from '@/mixins/split'
const session = JSON.parse(Cookies.get('sessionData'))
import importData from '@/components/BtnPage/importData'
import exportData from '@/components/BtnPage/exportData'
import excSolution from '@/components/BtnPage/excSolution'

export default {
    name: 'pre_cadreReg_list',
    components: { slider, tableContainer, importData, exportData, excSolution },
    mixins: [pagination, tableInterface, split],
    props: {
        heightPercentage: {
            type: Number,
            default: 1
        },
        hasTab: {
            type: Boolean,
            default: false
        },
        masterTable: {
            type: Boolean,
            default: true
        }
    },
    data() {
        return {
            formId: '2304',
            // 冻结列数量

            fixedColumns: 0,

            isOpen: true,

            leftTabName:

						'first',

            treeProps: {

            },
            tree: {

            },
            dictValues: {},
            hasCommonFilter: true,
            commonFilter: '',
            commonPlaceholder:
				'' +

								'工号,' +

								'姓名' +

				'',

            commonFilterArr: [

                'EMPVEMPLOYEE_EMPCODE',

                'EMPVEMPLOYEE_CNAME'

            ],
            filterData: {

                EMPVEMPLOYEE_DEPID: '',

                EMPPREPARCADREREG_CADREGRADE: '',

                EMPVEMPLOYEE_EMPCODE: '',

                EMPVEMPLOYEE_CNAME: '',

                ORGVORGANIZATION_ORGCODE: ''

            },
            showRowColumn: [

                { formColumnId: '42388', relcolumnId: 'EMPVEMPLOYEE_EMPCODE', columnId: 'EMPVEMPLOYEE_EMPCODE', columnName: '工号' },

                { formColumnId: '42389', relcolumnId: 'EMPVEMPLOYEE_CNAME', columnId: 'EMPVEMPLOYEE_CNAME', columnName: '姓名' },

                { formColumnId: '42390', relcolumnId: 'EMPVEMPLOYEE_ENAME', columnId: 'EMPVEMPLOYEE_ENAME', columnName: '英文名' },

                { formColumnId: '42385', relcolumnId: 'EMPVEMPLOYEE_COMPID', columnId: 'EMPVEMPLOYEE_COMPID_DICTNAME', columnName: '公司' },

                { formColumnId: '42386', relcolumnId: 'EMPVEMPLOYEE_DEPID', columnId: 'EMPVEMPLOYEE_DEPID_DICTNAME', columnName: '部门' },

                { formColumnId: '42387', relcolumnId: 'EMPVEMPLOYEE_JOBID', columnId: 'EMPVEMPLOYEE_JOBID_DICTNAME', columnName: '岗位' },

                { formColumnId: '42394', relcolumnId: 'EMPVEMPLOYEE_JOINDATE', columnId: 'EMPVEMPLOYEE_JOINDATE_NEWDATE', columnName: '入职日期' },

                { formColumnId: '42399', relcolumnId: 'EMPPREPARCADREREG_CADRETYPE', columnId: 'EMPPREPARCADREREG_CADRETYPE_DICTNAME', columnName: '党务序列' },

                { formColumnId: '42400', relcolumnId: 'EMPPREPARCADREREG_CADREGRADE', columnId: 'EMPPREPARCADREREG_CADREGRADE_DICTNAME', columnName: '后备职务级别' },

                { formColumnId: '62714', relcolumnId: 'EMPPREPARCADREREG_JOBTITLE', columnId: 'EMPPREPARCADREREG_JOBTITLE_DICTNAME', columnName: '职务名称' },

                { formColumnId: '42403', relcolumnId: 'EMPPREPARCADREREG_REASON', columnId: 'EMPPREPARCADREREG_REASON', columnName: '入库原因' },

                { formColumnId: '42404', relcolumnId: 'EMPPREPARCADREREG_VALIDDATE', columnId: 'EMPPREPARCADREREG_VALIDDATE_NEWDATE', columnName: '入库日期' },

                { formColumnId: '59756', relcolumnId: 'EMPPREPARCADREREG_CADRESTATUS', columnId: 'EMPPREPARCADREREG_CADRESTATUS_DICTNAME', columnName: '状态' },

                { formColumnId: '42405', relcolumnId: 'EMPPREPARCADREREG_REMARK', columnId: 'EMPPREPARCADREREG_REMARK', columnName: '备注' }

            ],
            list: [],
            listLoading: true,
            // 字段权限
            fieldValid: {},
            buttonValid: {},
            buttonList: [

                { buttonName: '引入员工', icon: 'el-icon-plus', buttonId: 2616, colorType: 'primary' },

                { buttonName: '修改', icon: 'el-icon-plus', buttonId: 2617, colorType: 'primary' },

                { buttonName: '删除', icon: 'el-icon-plus', buttonId: 3238, colorType: 'primary' },

                { buttonName: '生效', icon: 'el-icon-plus', buttonId: 3237, colorType: 'primary' },

                { buttonName: '导入', icon: 'el-icon-plus', buttonId: 6863, colorType: 'primary' },

                { buttonName: '导出', icon: 'el-icon-plus', buttonId: 6864, colorType: 'primary' },

                { buttonName: '批量修改', icon: 'el-icon-plus', buttonId: 9717, colorType: 'primary' }

            ],
            sortParams: {},

            dialogImportVisible: false,
            importExcelData: {
                formId: 2304,
                templateFileid: 0,
                templateFilename: '',
                buttonId: 6863
            },

            dialogExportVisible: false,
            exportExcelData: {
                formId: 2304,
                formFieldsize: 0,
                filename: '后备干部登记信息',
                buttonId: 6864,
                filterData: this.filterData,
                requestParam: this.requestParam
            },

            requestParam: {

                'ORGVORGANIZATION_ORGCODE': ''

            },
            userIds: ''
        }
    },
    async created() {
        this.$eventBus.$on('common-filter', (...args) => {
            this.commonFilter = args[0]
            this.commonFilterArr.forEach(item => {
                this.filterData[item] = this.commonFilter
            })
        }, this)
        this.$eventBus.$on('zhubiaochuandi', (...args) => {
            const row = args[0]
            // 只有非主表且有参数时才能去接收主表转过来的参数
            if (!this.masterTable && row) {
                this.requestParam = {

                    'ORGVORGANIZATION_ORGCODE': row.ORGVORGANIZATION_ORGCODE

                }
                this._cardformInitData()
            }
        }, this)
    },
    methods: {
        searchForm() {
            this._cardformInitData()
        },
        resetForm() {
            this.filterData = {

                EMPVEMPLOYEE_DEPID: '',

                EMPPREPARCADREREG_CADREGRADE: '',

                EMPVEMPLOYEE_EMPCODE: '',

                EMPVEMPLOYEE_CNAME: '',

                ORGVORGANIZATION_ORGCODE: ''

            }
            this.userIds = ''
        },
        toggleSlider(val) {
            this.isOpen = !val
            this.defaultPercent = val ? 2 : 20
            console.log(this.defaultPercent)
            this.$refs.split.onSetPercent(this.defaultPercent)
        },
        handleLeftTabClick(tab, event) {
            console.log(tab, event)
        },
        // 懒加载树节点数据
        loadNode(node, resolve) {

        },
        // 过滤树节点
        filterNode(value, data) {
            if (!value) return true
            return data.label.indexOf(value) !== -1
        },
        handleNodeClick(data) {
            this.filterData.ORGVORGANIZATION_ORGCODE = data.ORGVORGANIZATION_ORGCODE

            this.searchForm()
        },
        handleCheck(checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys) {
            console.log(checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys)
        },
        loadMore() {
            this._cardformInitData('loadMore')
        },
        onRowButtonClick(e) {
            var buttonId = e.buttonId
            var selectData = e.list
            var param = {}

            if (buttonId === 2616) {
                param.formId = this.formId
                param.intrToId = 46
                param.intrButtonId = buttonId
                this.gotoMyehrPath('/form/cadreManage/Get_cadreManage/emp_Registrationcadres/pre_cadreIntro_list', param, '后备干部引入', false)
            }

            if (buttonId === 2617) {
                param.isInit = 'true'

                param.EMPPREPARCADREREG_ID = selectData[0].EMPPREPARCADREREG_ID

                this.gotoMyehrPath('/form/cadreManage/Get_cadreManage/emp_Registrationcadres/pre_cadreReg_edit', param, '后备干部登记修改', false)
            }

            if (buttonId === 3238) {
                this.$confirm('此操作将删除数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    param.formId = this.formId
                    param.params = selectData
                    var recode = removeDataByButton(param)
                    console.log(recode)
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
            }

            if (buttonId === 3237) {
                console.log(selectData, '选中行')

                var EMPPREPARCADREREG_ID_Data
                var EMPPREPARCADREREG_ID_Datas = []
                for (var i = 0; i < selectData.length; i++) {
                    EMPPREPARCADREREG_ID_Datas.push(selectData[i].EMPPREPARCADREREG_ID)
                }
                EMPPREPARCADREREG_ID_Data = EMPPREPARCADREREG_ID_Datas.join(',')

                var paramsMap = { 'c_42395': EMPPREPARCADREREG_ID_Data, 's_userid': session['userid'] }
                var data = { 'formId': this.formId, 'buttonId': buttonId, 'params': paramsMap, 'containerParam': {}}
                executeSql(data).then(res => {
                    if (res[0] === '000000') {
                        this.$message({
                            type: 'success',
                            message: '执行成功!'
                        })
                    } else {
                        this.$message({
                            type: 'info',
                            message: res[1]
                        })
                    }
                })
            }

            if (buttonId === 6863) {
                this.dialogImportVisible = true
            }

            if (buttonId === 6864) {
                this.dialogExportVisible = true
                this.exportExcelData.requestParam = this.requestParam
                this.exportExcelData.filterData = this.filterData
            }

            if (buttonId === 9717) {

            }
        },
        onSortClick(e) {
            this.sortParams = {}
            this.sortParams[e.prop] = e.order === 'ascending' ? 'asc' : 'desc'
            this._cardformInitData()
        }
    }
}
</script>
